package keye.document_manage.gui;

import java.awt.Color;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;

public class MyTable extends  JTable{

	private static final long serialVersionUID = 1L;
	
	private Color gridColor = new Color(236,233,216);//网格颜色
	private int rowHeight = 30;//行高度
	private MyTableCellRenderer cellRenderer;
	public MyTable() {}
	
	public MyTable(TableModel tableModel) {
		this(tableModel,null,null);
	}
	
	public MyTable(TableModel tableModel, TableColumnModel columnModel) {
		this(tableModel, columnModel, null);
	}
	public MyTable(TableModel tableModel, TableColumnModel columnModel,ListSelectionModel listSelectionModel) {
		super(tableModel, columnModel,listSelectionModel);
		setGridColor(gridColor);
		setRowHeight(rowHeight);
		cellRenderer = new MyTableCellRenderer();
	}
	
	@Override
	public JTableHeader getTableHeader() {
		JTableHeader tableHeader = super.getTableHeader();  
//      tableHeader.setReorderingAllowed(false);//表格列不可移动  
        DefaultTableCellRenderer hr = (DefaultTableCellRenderer) tableHeader.getDefaultRenderer();  
        hr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);//列名居中  
        return tableHeader;  
	}
	
	@Override
	public TableCellRenderer getCellRenderer(int row, int column) {
//		System.out.println("getCellRenderer column:"+column+"  row:"+row);
		return cellRenderer;
	}
}
